package com.dehui.traders.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.view.View;

import com.dehui.traders.BR;
import com.dehui.traders.R;
import com.dehui.traders.adapter.TabAdapter;
import com.dehui.traders.databinding.FragmentInfomationBinding;
import com.dehui.traders.enums.InformationTab;
import com.dehui.traders.enums.MarketTab;
import com.dehui.traders.ui.viewmodle.InfomationViewModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseFragment;

/**
 * Created by hqq on 18.3.30.
 */

public class InfomationFragment extends BaseFragment<FragmentInfomationBinding,InfomationViewModel>{

    @Override
    public int initContentView() {
        return R.layout.fragment_infomation;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public InfomationViewModel initViewModel() {
        return new InfomationViewModel();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initTab();
    }

    private void initTab() {
        List<Fragment> list_fragment = new ArrayList<>();
        List<String> list_title = Arrays.asList(getResources().getStringArray(R.array.home_information_tab));
        binding.tablayoutInformation.setTabMode(TabLayout.MODE_FIXED);
        for (String title: list_title){
            binding.tablayoutInformation.addTab(binding.tablayoutInformation.newTab().setText(title));
        }

        InformationTab[] marketTabs = InformationTab.values();
        for (InformationTab tab: marketTabs){
            Fragment fragment = Fragment.instantiate(getActivity(), tab.clzName);
            list_fragment.add(fragment);
        }

        TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager(), list_fragment, list_title);
        binding.viewpagerInformation.setAdapter(tabAdapter);
        binding.tablayoutInformation.setupWithViewPager(binding.viewpagerInformation);
    }
}
